<?php

namespace app\backstage\service;

use think\Db;

class UserService
{
	protected static $table = 'user';

	/**
	 * 分页获取列表
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T22:38:21+0800
	 * @param    [type]                   $whereMap [description]
	 * @param    [type]                   $order    [description]
	 * @param    integer                  $pageSize [description]
	 * @return   [type]                             [description]
	 */
	public static function pageList($whereMap, $order, $pageSize = 10)
	{
		return Db::name(self::$table)->where($whereMap)->order($order)->paginate($pageSize);
	}

	/**
	 * 通过字段获取信息
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-09T22:32:38+0800
	 * @param    [type]                   $field  [description]
	 * @param    [type]                   $value  [description]
	 * @param    string                   $fields [description]
	 * @return   [type]                           [description]
	 */
	public static function getInfo($field, $value, $fields = '*')
	{
		return Db::name(self::$table)->where($field, $value)->field($fields)->find();
	}

	/**
	 * 添加
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-09T22:35:17+0800
	 * @param    [type]                   $data [description]
	 */
	public static function add($data)
	{
		$result = Db::name($this->table)->insert($data);
		if (!$result) {
			return false;
		}
		return true;
	}

	/**
	 * 更新
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-09T22:53:18+0800
	 * @param    [type]                   $field [description]
	 * @param    [type]                   $value [description]
	 * @param    [type]                   $data  [description]
	 * @return   [type]                          [description]
	 */
	public static function update($field, $value, $data) 
	{
		$result = Db::name($this->table)->where($field, $value)->update($data);
		if (!$result) {
			return false;
		}
		return true;
	}

	/**
	 * 通过id删除
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-09T23:05:22+0800
	 * @param    [type]                   $id [description]
	 * @return   [type]                       [description]
	 */
	public static function del($id)
	{
		$result = Db::name($this->table)->where('id', $id)->delete();
		if (!$result) {
			return false;
		}
		return true;
	}
}